package nl.weeaboo.sh;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.media.opengl.GLCanvas;
import javax.swing.ImageIcon;

public class GameFrame extends nl.weeaboo.game.GameFrame {

	private static final String TITLE = "Scarlet Heart v0.1.999";
	private static final ImageIcon PROGRAM_ICON = new ImageIcon(
			Game.class.getResource("res/app_icon.png"));

	public static final int defaultWidth = 800;
	public static final int defaultHeight = 480;
	
	public GameFrame(Game g) {
		super(g, TITLE, PROGRAM_ICON, 60, false, false, g.config.getUseTrueFullscreen());
		
		GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
		float ratio = 4f / 3f;
		if (gd.getDisplayMode() != null) {
			ratio = (float)gd.getDisplayMode().getWidth() /  gd.getDisplayMode().getHeight();
		}

		if (ratio <= 4f/3f) { //4:3
			setFullScreenSize(new Dimension(800, 600));
		} else if (ratio <= 16f/10f) { //16:10
			setFullScreenSize(new Dimension(1280, 800));
		} else { //16:9
			setFullScreenSize(new Dimension(1280, 720));
		}		
	}
	
	//Functions
	
	//Getters
	
	//Setters
	protected void setFrameBounds(Frame frame, GLCanvas canvas) {
		canvas.setPreferredSize(new Dimension(defaultWidth, defaultHeight));
		frame.pack();
		frame.setLocationRelativeTo(null);
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}
	
}
